package com.lineage.server.datatables.lock;

import com.lineage.server.datatables.sql.ServerTable;
import com.lineage.server.datatables.storage.ServerStorage;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class ServerReading {
  private final Lock _lock = new ReentrantLock(true);
  
  private final ServerStorage _storage = (ServerStorage)new ServerTable();
  
  private static ServerReading _instance;
  
  public static ServerReading get() {
    if (_instance == null)
      _instance = new ServerReading(); 
    return _instance;
  }
  
  public void load() {
    this._lock.lock();
    try {
      this._storage.load();
    } finally {
      this._lock.unlock();
    } 
  }
  
  public int minId() {
    this._lock.lock();
    int temp = 0;
    try {
      temp = this._storage.minId();
    } finally {
      this._lock.unlock();
    } 
    return temp;
  }
  
  public int maxId() {
    this._lock.lock();
    int temp = 0;
    try {
      temp = this._storage.maxId();
    } finally {
      this._lock.unlock();
    } 
    return temp;
  }
  
  public void isStop() {
    this._lock.lock();
    try {
      this._storage.isStop();
    } finally {
      this._lock.unlock();
    } 
  }
}
